<template>
	<view>
		<view class="techno-box">
			<view class="techno-input">
				<textarea style="height: 120px;" v-model="url" placeholder="请粘贴视频地址" placeholder-style="color:rgba(255,255,255,.5);"></textarea>
			</view>
			<view class="techno-btn" @click="getData">
				解析
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: '',
				dataSource: {}
			}
		},
		onShow() {
			uni.getClipboardData({
				success(res) {
					this.url = res.data;
				}
			});
		},
		methods: {
			getData() {
				if (this.url === "" || !this.url.includes('http')) {
					uni.showModal({
						title: '提示',
						content: '请输入解析地址',
						showCancel: false
					});
					return false;
				}

				let params = encodeURIComponent(this.removal(this.url));

				this.$request.get('reptile/douyin/' + params, {}).then(res => {
					let {
						code,
						msg
					} = res;
					if (code === 1) {
						uni.setStorageSync('video_params', JSON.stringify(res));
						uni.navigateTo({
							url: "/pages/video/video"
						});
					} else {
						uni.showModal({
							title: '提示',
							content: msg,
							showCancel: false
						});
					}
					console.log(res)
				})
			},
			removal(str) {
				str = str.replace(/[\u4e00-\u9fa5]/g, ""); //去除中文 
				str = str.replace(
					/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g,
					""); // 去掉特殊字符 
				str = str.replace(/[&\|\\\*^%$#@\-]/g, ""); //去除#
				return str.trim();
			}
		}
	}
</script>

<style lang="less" scoped>
	.techno-box {
		background: linear-gradient(to bottom, #49BDAD, #6a67c7);
		height: 100vh;
		position: relative;
		padding-top: 5vh;

		.techno-input {
			width: 90vw;
			margin-left: 5vw;
			background: rgba(0, 0, 0, 0);
			border: 1px solid #FFFFFF;
			border-radius: 5px;
		}

		.techno-btn {
			width: 90vw;
			height: 40px;
			line-height: 40px;
			margin: 3vh 5vw 0vw 5vw;
			background: rgba(0, 0, 0, 0);
			border: 1px solid #FFFFFF;
			border-radius: 5px;
			color: #FFFFFF;
			text-align: center;
		}
	}
</style>
